package com.lihui.lesson08;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 功能描述
 *
 * @author wileda
 * @date 2023/03/07  15:18
 */
public class Demo_801 {
    public static void main(String[] args) throws InterruptedException {
        //基于CAS的源子类
        AtomicInteger atomicInteger = new AtomicInteger();
        
        //创建两个线程，进行自增
        Thread t1 = new Thread(() ->{
            for (int i = 0; i < 5000; i++) {
                //通过调用方法进行自增操作
                atomicInteger.getAndIncrement();
            }
        });

        Thread t2 = new Thread(() ->{
            for (int i = 0; i < 5000; i++) {
                atomicInteger.getAndIncrement();
            }
        });

        t1.start();
        t2.start();

        t1.join();
        t2.join();

        System.out.println("执行结果:" + atomicInteger.get());
    }
}
